<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>Hello APP</title>
    <link rel="stylesheet" type="text/css" href="../css/aui.css" />
	<style>

	</style>
</head>
<body>
    <section class="aui-content aui-margin-t-15">
        <ul class="aui-list aui-form-list">
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">
                        流程
                    </div>
                    <div class="aui-list-item-input">
                        <select id="process-list">
                        </select>
                    </div>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">
                        工作名称
                    </div>
                    <div class="aui-list-item-input">
                        <!--<input id="id_working_name" type="text" placeholder="工作名称">-->
                        <textarea id="id_working_name" placeholder="工作名称"></textarea>
                    </div>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">
                        时间
                    </div>
                    <div class="aui-list-item-input">
                        <input id="id_time" onclick="selectTime()" readonly="readonly" type="text" placeholder="选择时间">
                    </div>
                </div>
            </li>
        </ul>
    </section>
    <div  style="display: block" class="aui-content aui-margin-15">
    <div class="aui-btn aui-btn-info aui-btn-block aui-btn-sm " onclick="addWork()">保存</div>
    </div>
</body>
<script type="text/javascript" src="../script/zepto.min.js" ></script>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript">
    apiready = function(){
        api.parseTapmode();

        //获取流程
        api.ajax({
    		    url: ServeUrl+'m=Workflow&a=getProcessDesign',
    		    method: 'post',
    		},function(ret, err){
    			//	alert(JSON.stringify(ret));
            if (ret.status == 1) {
                var html = '<option value="">请选择</option>';
                for (var i = 0; i < ret.data.length; i++) {
                   html += '<option value="'+ret.data[i].id+'">'+ret.data[i].process_name+'</option>';
                }
            }
            $("#process-list").append(html);
    		});

    };

    $("#process-list").change(function(){
        var myDate = new Date();
        var nowtime = myDate.toLocaleString();
        var username = $api.getStorage("username");
        var index=document.getElementById("process-list").selectedIndex;
        var text = document.getElementById("process-list").options[index].text;
        var content = username+" "+text+" ("+nowtime+")";
        $("#id_working_name").val(content);
    });

    function addWork(){
        var process_design_id = $("#process-list").val();
        var working_name = $("#id_working_name").val();
        api.openWin({
            name: "workform_add",
            url: 'workform_add_win.html',
            pageParam: {
                username : $api.getStorage("username"),
                process_design_id : process_design_id,
                working_name : working_name
            }
        });
        /*api.ajax({
            url: ServeUrl+'m=Workflow&a=addWork',
            method: 'post',
            data : {
                values : {
                    username : $api.getStorage("username"),
                    process_design_id : process_design_id,
                    working_name : working_name
                }
            }
        },function(ret, err){
          alert(JSON.stringify(ret));
            if (ret.status == 1) {

            }
        });*/


    }

    function selectTime(){
        api.openPicker({
          type: 'time',
          title: '选择时间'
        }, function(ret, err) {
          if (ret) {
              $("#id_time").val(ret.hour+':'+ret.minute);
              alert(JSON.stringify(ret));
          } else {
              alert(JSON.stringify(err));
          }
        });

    }
</script>
</html>
